package yxy.game.pm2.module.tip.checker;

import java.util.Map;

import yxy.apple.util.PubSub.MethodSubscriber;
import yxy.apple.util.PubSub.SubscriptionMethod;
import yxy.game.pm2.bean.pubsub.TaskPublisher;
import yxy.game.pm2.bean.pubsub.TaskPublisher.TaskSubscription;
import yxy.game.pm2.bean.task.Task;
import yxy.game.pm2.module.daily.DailyModule;
import yxy.game.pm2.module.tip.TipHandle;
import yxy.game.pm2.module.tip.TipType;

public class TipSubscriber_日常任务 extends MethodSubscriber {

	static private TipSubscriber_日常任务 instance;

	public static TipSubscriber_日常任务 getInstance() {
		if (instance == null) {
			instance = new TipSubscriber_日常任务();
			instance.init();
		}
		return instance;
	}

	private void init() {
		TaskPublisher.getInstance().subscribe(this);
	}

	private TipSubscriber_日常任务() {
	}

	@SubscriptionMethod(Type = TaskSubscription.class)
	public void receive(TaskSubscription subscription) {
//		System.err.println("订阅更新Task");
		String playerCode = subscription.getPlayerCode();
		Map<String, Task> allTask = subscription.getAllTask();
		DailyModule dailyModule = DailyModule.get(playerCode);
		for (String taskCode : dailyModule.getTaskCodes()) {
			Task task = allTask.get(taskCode);
			if (task == null) {
				continue;
			}
			if (task.isFinish() && !task.isReward()) {
				new TipHandle().updateTip(playerCode, TipType.征战_日常_任务切页, true);
				return;
			}
		}
		new TipHandle().updateTip(playerCode, TipType.征战_日常_任务切页, false);
	}

}
